#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

#define InitSize 10
typedef int ElemType;
typedef struct {
    ElemType *data;
    int length;
    int MaxSize;
}SqList;

void initList(SqList *L);
void increaseSize(SqList *L, int len);
bool listInsert(SqList *L, int index, ElemType elem);
bool listDelete(SqList *L, int index, ElemType *elem);
int locateElem(SqList L, ElemType elem);

int main(){
    SqList L;
    initList(&L);
    return 0;
}

void initList(SqList *L){
    L->MaxSize = InitSize;
    L->data = (ElemType*)malloc(sizeof(ElemType)*InitSize);
    L->length = 0; 
}

void increaseSize(SqList *L, int len){
    ElemType *temp = L->data;
    L->data = (ElemType*)malloc(sizeof(ElemType)*L->MaxSize+len);
    for(int i=0;i<L->length;i++){
        L->data[i] = temp[i];
    }
    L->MaxSize = L->MaxSize+len;
    free(temp);
}

bool listInsert(SqList *L, int index, ElemType elem){
    if(index<1||index>L->length+1){
        return false;
    }
    if(L->length>=L->MaxSize){
        return false;
    }
    for(int i=L->length;i>=index;i--){
        L->data[i] = L->data[i-1];
    }
    L->data[index-1] = elem;
    L->length+=1;
    return true;
}

bool listDelete(SqList *L, int index, ElemType *elem){
    if(index<1||index>L->length){
        return false;
    }
    *elem = L->data[index-1];
    for(int i=index-1;i<L->length;i++){
        L->data[i] = L->data[i+1];
    }
    L->length-=1;
    return true;
}

int locateElem(SqList L, ElemType elem){
    int index = -1;
    for(int i=0;i<L.length;i++){
        if(L.data[i] == elem){
            index = i+1;
            break;
        }
    }
    return index;
}